<!--
/********************************************************* 
 * LICENSE: LICENSE-Free_CN.MD
 * 
 * Author: Numberwolf - ChangYanlong
 * QQ: 531365872
 * QQ Group:925466059
 * Wechat: numberwolf11
 * Discord: numberwolf#8694
 * E-Mail: porschegt23@foxmail.com
 * Github: https://github.com/numberwolf/h265web.js
 * 
 * 作者: 小老虎(Numberwolf)(常炎隆)
 * QQ: 531365872
 * QQ群: 531365872
 * 微信: numberwolf11
 * Discord: numberwolf#8694
 * 邮箱: porschegt23@foxmail.com
 * 博客: https://www.jianshu.com/u/9c09c1e00fd1
 * Github: https://github.com/numberwolf/h265web.js
 * 
 **********************************************************/
-->
<!DOCType html>
<html>
<head>
    <link href="/favicon.ico" rel="icon" type="image/x-icon" />
    <meta charset="utf-8">
    <title>TsDemuxerJS - https://github.com/numberwolf/h265web.js</title>
    <meta charset="utf-8" name="author" content="ChangYanlong">
    <meta charset="utf-8" name="email" content="porschegt23@foxmail.com">
    <meta charset="utf-8" name="discord" content="numberwolf#8694">
    <meta charset="utf-8" name="github" content="https://github.com/numberwolf/h265web.js">
    <script src='dist/play.js'></script>
</head>
<body>
    <script>
        var demuxCount = 0;
        // var url264 = "/res/veilside264.ts";
        var url = "/res/veilside2.ts";
        var url = "/res/veilside.ts";
        //var url = "/res/veilside265_an.ts";
        //var url = "/res/xinxiaomen.mp4";
        var config = {};
        var demuxer = makeTsDemuxerJs(config);

        // bind callback
        demuxer.onReady = () => {
            // do sth
            demuxer.demuxURL(url);
        };

        demuxer.onDemuxed = () => {
            if (demuxCount > 1) {
                return;
            }
            demuxCount += 1;
            var mediaInfo = demuxer.readMediaInfo();
            console.log(mediaInfo);

            var extInfo = demuxer.readExtensionInfo();
            console.log(extInfo);

            var readData = null;
            var vcount = 0;
            var acount = 0;
            while(1) {
                readData = demuxer.readPacket();
                if (readData.size <= 0) {
                    break;
                }
                if (readData.type == 0) {
                    vcount++;
                } else {
                    acount++;
                    // console.log(readData.ptime, readData.size);
                    // break; // debug
                }
                console.log(readData);
                /*
                 * Video readData.data is uint8array
                 * Audio readData.data is list of {pts,uint8array}
                 */
                // console.log(readData);
                // break; // debug
            }
            console.log(vcount, acount);
        };

        // init demuxer framework
        demuxer.initDemuxer();

        // setTimeout(() => {
        //     // next
        //     console.log("start 264=====================");
        //     // demuxer.demuxURL(url);
        //     fetch(url264)
        //     .then(res => res.arrayBuffer())
        //     .then(streamBuffer => {
        //         streamBuffer.fileStart = 0;
        //         // array buffer to unit8array
        //         let streamUint8Buf = new Uint8Array(streamBuffer);
        //         demuxer.demuxUint8Buf(streamUint8Buf);
        //     });
        // }, 5000);


	</script>
</body>
</html>
